package com.qfedu.dao.impl;

import com.qfedu.dao.DeveloperDao;
import com.qfedu.model.Developer;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class DeveloperDaoImpl implements DeveloperDao {
    @Resource
    private JdbcTemplate jdbcTemplate;

    //查询所有
    @Override
    public List<Developer> selectAll() {
        String sql = "select * from developer";
        List<Developer> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Developer.class));
        return list;
    }

    //新增
    @Override
    public int add(Developer developer) {
        String sql = "insert into developer values (?,?,?,?)";
        int update = jdbcTemplate.update(sql, developer.getDid(), developer.getDname(), developer.getUpdatetime(), developer.getStatus());
        return update;

    }

    //删除
    @Override
    public int delete(String id) {
        String sql = "delete from developer where did = ?";
        int delete = jdbcTemplate.update(sql, id);
        return delete;

    }
}
